home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / mole.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  2KB  |  86 lines

  1. /***************************************************************************
  2.   vidhrdw/mole.c
  3.   Functions to emulate the video hardware of Mole Attack!.
  4.   Mole Attack's Video hardware is essentially two banks of 512 characters.
  5.   The program uses a single byte to indicate which character goes in each location,
  6.   and uses a control location (0x8400) to select the character sets
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12. static int tile_bank;
  13. static UINT16 *tile_data;
  14. #define NUM_ROWS 25
  15. #define NUM_COLS 40
  16. #define NUM_TILES (NUM_ROWS*NUM_COLS)
  17.  
  18. void moleattack_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom){
  19.     int i;
  20.     for( i=0; i<8; i++ ){
  21.         colortable[i] = i;
  22.         *palette++ = (i&1)?0xff:0x00;
  23.         *palette++ = (i&4)?0xff:0x00;
  24.         *palette++ = (i&2)?0xff:0x00;
  25.     }
  26. }
  27.  
  28. int moleattack_vh_start( void ){
  29.     tile_data = (UINT16 *)malloc( NUM_TILES*sizeof(UINT16) );
  30.     if( tile_data ){
  31.         dirtybuffer = malloc( NUM_TILES );
  32.         if( dirtybuffer ){
  33.             memset( dirtybuffer, 1, NUM_TILES );
  34.             return 0;
  35.         }
  36.         free( tile_data );
  37.     }
  38.     return 1; /* error */
  39. }
  40.  
  41. void moleattack_vh_stop( void ){
  42.     free( dirtybuffer );
  43.     free( tile_data );
  44. }
  45.  
  46. WRITE_HANDLER( moleattack_videoram_w ){
  47.     if( offset<NUM_TILES ){
  48.         if( tile_data[offset]!=data ){
  49.             dirtybuffer[offset] = 1;
  50.             tile_data[offset] = data | (tile_bank<<8);
  51.         }
  52.     }
  53.     else if( offset==0x3ff ){ /* hack!  erase screen */
  54.         memset( dirtybuffer, 1, NUM_TILES );
  55.         memset( tile_data, 0, NUM_TILES*sizeof(UINT16) );
  56.     }
  57. }
  58.  
  59. WRITE_HANDLER( moleattack_tilesetselector_w ){
  60.     tile_bank = data;
  61. }
  62.  
  63. void moleattack_vh_screenrefresh( struct osd_bitmap *bitmap, int full_refresh ){
  64.     int offs;
  65.  
  66.     if( full_refresh || palette_recalc() ){
  67.         memset( dirtybuffer, 1, NUM_TILES );
  68.     }
  69.  
  70.     for( offs=0; offs<NUM_TILES; offs++ ){
  71.         if( dirtybuffer[offs] ){
  72.             UINT16 code = tile_data[offs];
  73.             drawgfx( bitmap, Machine->gfx[(code&0x200)?1:0],
  74.                 code&0x1ff,
  75.                 0, /* color */
  76.                 0,0, /* no flip */
  77.                 (offs%NUM_COLS)*8, /* xpos */
  78.                 (offs/NUM_COLS)*8, /* ypos */
  79.                 0, /* no clip */
  80.                 TRANSPARENCY_NONE,0 );
  81.  
  82.             dirtybuffer[offs] = 0;
  83.         }
  84.     }
  85. }
  86.